package cn.zwxky.android.staff.Jurisdiction.OtherSectors;

import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.zwxky.android.staff.Follow.ArrangeAdapter;
import cn.zwxky.android.staff.Follow.ArrangeClickEvent;
import cn.zwxky.android.staff.Follow.ArrangeFollowActivity2;
import cn.zwxky.android.staff.Follow.NormalTaskBean;
import cn.zwxky.android.staff.Follow.NormalTaskEvent;
import cn.zwxky.android.staff.Jurisdiction.Marketplace.ReleaseTaskActivity;
import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.URLString;

/**
 * 其他部门任务列表
 * Created by Administrator on 2017/4/21 0021.
 */
@ContentView(R.layout.aty_other_task)
public class OtherTaskActivity extends LsfbActivity {

    /**
     * 点击刷新布局控件
     */
    @ViewInject(R.id.swiplayout)
    private SwipeRefreshLayout swipeRefreshLayout;

    /**
     * list列表
     */
    @ViewInject(R.id.dish_list)
    private RecyclerView dish_list;

    /**
     * RecyclerView的布局管理器
     */
    private RecyclerView.LayoutManager mlayoutManager;

    private List<NormalTaskBean.ListBean> mList;
    private ArrangeAdapter adapter;


    @Override
    public void initView() {
        mList = new ArrayList<>();
        adapter = new ArrangeAdapter(this, mList, R.layout.item_arrange);
        mlayoutManager = new LinearLayoutManager(this);//布局模式为listview方式
        dish_list.setLayoutManager(mlayoutManager);
        dish_list.setAdapter(adapter);

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getData();
            }
        });
    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.fg_back,R.id.fg_add})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fg_back:
                finish();
                break;
            case R.id.fg_add:
                startActivity(new Intent(this,ReleaseTaskActivity.class));
                break;
        }
    }

    @Override
    public void initData() {

    }


    /**
     * 获取数据
     */
    public void getData() {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("admin","1");
        new BaseInternet().getData_Get(URLString.NORMAL_TASK, hashMap, NormalTaskBean.class, new NormalTaskEvent<NormalTaskBean>(), true, true);
    }

    @EventAnnotation
    public void NormalTaskEvent(NormalTaskEvent<NormalTaskBean> event) {
        swipeRefreshLayout.setRefreshing(false);
        switch (event.getCode()) {
            case 200:
                mList.clear();
                mList.addAll(event.getData().getList());
                adapter.notifyDataSetChanged();
                break;
            default:
                mList.clear();
                adapter.notifyDataSetChanged();
                SN.SnackShow(dish_list, event.getMsg());
                break;
        }
    }

    @EventAnnotation
    public void ArrangeClickEvent(ArrangeClickEvent event) {
        startActivity(new Intent(this, ArrangeFollowActivity2.class).putExtra("id", event.getData()));
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }
}
